package com.monkeygroup.mygoplus.ecchat.ui.contact.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.ecchat.ui.contact.entity.ContactApplyDTO;

import java.util.List;

/**
 * Created by Administrator on 2017/5/24.
 */
public class ContactApplyAdapter extends BaseAdapter {
    private List<ContactApplyDTO> data = null;
    private Context mContext;
    private LayoutInflater inflater;

    public ContactApplyAdapter(Context context, List<ContactApplyDTO> data) {
        this.mContext = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (data != null) {
            return data.size();
        }

        return 0;
    }

    @Override
    public ContactApplyDTO getItem(int position) {
        if (data != null && data.size() > 0) {
            return data.get(position);
        }

        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_friend_apply, null);
            holder.head_icon = (ImageView) convertView.findViewById(R.id.head_icon);
            holder.item_name = (TextView) convertView.findViewById(R.id.item_name);
            holder.item_method = (TextView) convertView.findViewById(R.id.item_method);
            holder.add_icon = (ImageView) convertView.findViewById(R.id.add_icon);
            holder.item_state = (TextView) convertView.findViewById(R.id.item_state);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ContactApplyDTO item = getItem(position);
        holder.item_name.setText(item.getNickname());

        return convertView;
    }

    private class ViewHolder {
        ImageView head_icon;
        TextView item_name;
        TextView item_method;
        ImageView add_icon;
        TextView item_state;
    }
}